package com.example.ssmxuankeback.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
@Schema(name = "PageDTO", description = "分页结果")
public class PageVO<T> {
    @Schema(description = "总记录数")
    private Long total;

    @Schema(description = "总页数")
    private Long pages;

    @Schema(description = "当前页数据")
    private List<T> records;

    // 快速构造方法
    public static <T> PageVO<T> of(IPage<?> page, List<T> records) {
        return PageVO.<T>builder()
                .total(page.getTotal())
                .pages(page.getPages())
                .records(records)
                .build();
    }
}
